<!DOCTYPE html>
<html>
    <head>
        <!-- 页面meta -->
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>传智健康</title>
        <meta name="description" content="传智健康">
        <meta name="keywords" content="传智健康">
        <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
        <!-- 引入样式 -->
        <link rel="stylesheet" href="../plugins/elementui/index.css">
        <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
        <link rel="stylesheet" href="../css/style.css">
        <!-- 引入组件库 -->
        <script src="../js/vue.js"></script>
        <script src="../plugins/elementui/index.js"></script>
        <script type="text/javascript" src="../js/jquery.min.js"></script>
        <script src="../js/axios-0.18.0.js"></script>
    </head>
    <body class="hold-transition">
        <div id="app">
            <div class="content-header">
                <h1>预约管理<small>预约列表</small></h1>
                <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
                    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item>预约管理</el-breadcrumb-item>
                    <el-breadcrumb-item>预约列表</el-breadcrumb-item>
                </el-breadcrumb>
            </div>
            <div class="app-container">
                <div class="box">
                    <div class="filter-container">
                        <el-input placeholder="手机号" v-model="pagination.queryString" style="width: 200px;" class="filter-item"></el-input>
                        <el-button @click="findPage1()" class="dalfBut">查询</el-button>
                        <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                    </div>
                    <el-button size="mini" type="danger" @click="handleSelectionChange">批量取消</el-button>
                    <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row ref="multipleTable" >
                        <el-table-column  type="selection"  width="55"></el-table-column>
                        <el-table-column prop="orderDate" label="预约日期"  align="center" ></el-table-column>
                        <el-table-column prop="fileNumber" label="档案号" align="center"></el-table-column>
                        <el-table-column prop="name" label="姓名" align="center"></el-table-column>
                        <el-table-column prop="phoneNumber" label="手机号" align="center"></el-table-column>
                        <el-table-column prop="orderType" label="预约类型" align="center"></el-table-column>
                        <el-table-column prop="orderStatus" label="预约状态" align="center"></el-table-column>
                        <el-table-column label="操作" align="center">
                            <template slot-scope="scope">
                                <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">确认</el-button>
                                <el-button size="mini" type="danger" @click="handleDelete(scope.row)">取消</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <div class="pagination-container">
                        <el-pagination
                            class="pagiantion"
                            @current-change="handleCurrentChange"
                            :current-page="pagination.currentPage"
                            :page-size="pagination.pageSize"
                            layout="total, prev, pager, next, jumper"
                            :total="pagination.total">
                        </el-pagination>
                    </div>

                    <!-- 新增预约标签弹层 -->
                    <div class="add-form">
                        <el-dialog title="新增预约" :visible.sync="dialogFormVisible">
                            <template>
                                <el-tabs v-model="activeName" type="card">
                                    <el-tab-pane label="基本信息" name="first">
                                        <el-form label-position="right" label-width="100px" >
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="姓名">
                                                        <el-input v-model="formData.name"></el-input>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="身份证号码">
                                                        <el-input v-model="formData.idCard"></el-input>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>

                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="出生日期">
                                                        <el-date-picker type="date" placeholder="选择日期" v-model="formData.birthday" style="width: 100%;"></el-date-picker>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="手机号">
                                                        <el-input v-model="formData.phoneNumber"></el-input>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>

                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="性别">
                                                        <el-select v-model="formData.sex">
                                                            <el-option label="不限" value="0"></el-option>
                                                            <el-option label="男" value="1"></el-option>
                                                            <el-option label="女" value="2"></el-option>
                                                        </el-select>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="年龄">
                                                        <el-input v-model="formData.age"></el-input>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>

                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="婚姻状态">
                                                        <el-select v-model="formData.marriage">
                                                            <el-option label="已婚" value="married"></el-option>
                                                            <el-option label="未婚" value="single"></el-option>
                                                        </el-select>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="预约时间">
                                                        <el-date-picker type="date" placeholder="选择日期" v-model="formData.orderDate" style="width: 100%;"></el-date-picker>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>

                                        </el-form>
                                    </el-tab-pane>
                                    <el-tab-pane label="套餐信息" name="second">
                                        <div class="checkScrol">
                                            <table class="datatable">
                                                <thead>
                                                <tr>
                                                    <th>选择</th>
                                                    <th>套餐名称</th>
                                                    <th>适用人群</th>
                                                    <th>套餐介绍</th>
                                                </tr>
                                                </thead>
                                                <tbody>
                                                <tr v-for="s in tableData">
                                                    <td>
                                                        <input :id="s.id" v-model="setmealIds" type="checkbox" :value="s.id">
                                                    </td>
                                                    <td><label :for="s.id">{{s.name}}</label></td>
                                                    <td><label :for="s.id">{{s.sex}}</label></td>
                                                    <td><label :for="s.id">{{s.remark}}</label></td>
                                                </tr>
                                                </tbody>
                                            </table>
                                        </div>
                                    </el-tab-pane>
                                </el-tabs>
                            </template>
                            <div slot="footer" class="dialog-footer">
                                <el-button @click="dialogFormVisible = false">取消</el-button>
                                <el-button type="primary" @click="handleAdd()">确定</el-button>
                            </div>
                        </el-dialog>
                    </div>
                </div>
            </div>
        </div>
    </body>

    <script>
        var vue = new Vue({
            el: '#app',
            data:{
                pagination: {//分页相关模型数据
					  currentPage: 1,//当前页码
					  pageSize:10,//每页显示的记录数
					  total:10,//总记录数
					  queryString:null//查询条件
				},
				dataList: [
                    {
                        "orderType": "",
                        "phoneNumber": "",
                        "name": "",
                        "orderStatus": "",
                        "fileNumber": "",
                        "id": 1,
                        "orderDate": " "
                    }
                ],//当前页要展示的分页列表数据
                formData: {},//表单数据
                tableData:[],//新增表单中对应的套餐列表数据
                setmealIds:[],//新增表单中套餐对应的复选框，基于双向绑定可以进行回显和数据提交
                multipleSelection: [],
                dialogFormVisible: false,//增加表单是否可见

                rules: {//校验规则
                    idCard:[{ required: true, message: '身份证号码为必填项', trigger: 'blur' }],
                    name:[{ required: true, message: '姓名为必填项', trigger: 'blur' }]
                }
            },
            //1.1  钩子函数，VUE对象初始化完成后自动执行
            created() {
                //页面加载完毕后查询所有数据
                this.findPage();
            },
            methods: {

                //2.新增预约(电话预约)
                handleAdd () {
                    //发送ajax请求，将表单数据提交到后台进行处理
                    axios.post("/ordersettinglist/add.do?setmealIds=" + this.setmealIds,this.formData).then((res) => {
                        //关闭新增窗口
                        this.dialogFormVisible = false;
                        if(res.data.flag){
                            //操作成功
                            this.$message({
                                type:'success',
                                message:res.data.message
                            });
                        }else{
                            //操作失败
                            this.$message.error(res.data.message);
                        }
                    }).finally(() => {
                        //重新进行分页查询
                        this.findPage();
                    });
                },
                findPage1() {
                    this.pagination.currentPage = 1;
                    this.findPage();
                },

                //2. 分页查询
                findPage() {
                    var _this=this;
                    var params={currentPage:this.pagination.currentPage,
                        pageSize:this.pagination.pageSize,
                        queryString:this.pagination.queryString
                    };
                    axios.post("/ordersettinglist/findPage.do",params)
                        .then((res)=>{
                           _this.pagination.total= res.data.total;
                           _this.dataList= res.data.rows;
                        })
                },

                // 重置表单
                resetForm() {
                this.formData={};
                this.activeName = 'first';
                this.setmealIds = [];
                },
                // 弹出添加窗口
                handleCreate() {
                    this.dialogFormVisible=true;
                    this.resetForm();
                    axios.post("/ordersettinglist/findAll.do").then((res) => {
                        if(res.data.flag){
                            //查询套餐数据成功
                            this.tableData = res.data.data;
                        }else{
                            //查询套餐数据失败
                            this.$message.error(res.data.message);
                        }
                    });
                },

                // 3.确认预约，修改用户预约状态
                handleUpdate(row) {

                    // 再查询当前行预约的最新数据回写给formDate
                       axios.post("/ordersettinglist/updateById.do?id="+row.id).then((res)=>{
                           if (res.data.flag) {

                               this.$message(
                                   {
                                       message:res.data.message,
                                       type:"success"
                                   }
                               )
                           }else{
                               //查询失败，弹出提升
                               this.$message.error(res.data.message)
                           }
                       }).finally(
                           this.findPage()
                       )
                },

                //切换页码
                handleCurrentChange(currentPage) {
                 this.pagination.currentPage=currentPage;
                 //1.页码改变后重新给当前页码赋值   2.再次调用分页查询方法
                 this.findPage();

                },

                showMessage(r){
                    if(r == 'Error: Request failed with status code 403'){
                        //权限不足
                        this.$message.error('无访问权限');
                        return;
                    }else{
                        this.$message.error('未知错误');
                        return;
                    }
                },

                // 4.用户取消预约，删除预约数据
                handleDelete(row) {

                    //ID值为每一个检查项的主建值
                    this.$confirm("您确定要删除吗？",'提示',{
                        type:'warning'
                    }).then(()=>{
                        //用户点击确定删除，发送ajax请求；
                        axios.post("/ordersettinglist/deleteById.do?id="+row.id).then((res)=>{
                            if (res.data.flag) {
                                this.$message({
                                    message:res.data.message,
                                    type:'success'
                                });
                                //再次查询检查项
                                this.findPage();
                            } else {
                                this.$message.error(res.data.message);

                            }
                        }).catch((r)=>{
                            // 用户访问权限不足的提示；
                            this.showMessage(r);
                        })
                    }).catch(()=>{
                        //用户点击取消，则取消删除操作
                        this.$message({
                            message:'操作已取消!',
                            type:'info'
                        })
                    })

                },
                //5.批量取消
                handleSelectionChange(row) {

                    //ID值为每一个检查项的主建值
                    this.$confirm("您确定要删除吗？",'提示',{
                        type:'warning'
                    }).then(()=>{
                        //用户点击确定删除，发送ajax请求；
                        axios.post("/ordersettinglist/deleteByIds.do?id="+row.id).then((res)=>{
                            if (res.data.flag) {
                                this.$message({
                                    message:res.data.message,
                                    type:'success'
                                });
                                //再次查询检查项
                                this.findPage();
                            } else {
                                this.$message.error(res.data.message);

                            }
                        }).catch((r)=>{
                            // 用户访问权限不足的提示；
                            this.showMessage(r);
                        })
                    }).catch(()=>{
                        //用户点击取消，则取消删除操作
                        this.$message({
                            message:'操作已取消!',
                            type:'info'
                        })
                    })
                },
            }
        })
    </script>

</html>